#include "SpriteManager.h"
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include "DrawableSprite.h"
#include <vector>
#include "Background.h"

SpriteManager::SpriteManager() {};

bool SpriteManager::init()
{
return true;
}

std::vector<sf::Sprite> SpriteManager::getSpriteList()
{
    return _lstSprite;
}

void SpriteManager::addSprite(sf::Sprite& sprite)
{
    _lstSprite.push_back(sprite);
}

bool SpriteManager::prepareSprite(sf::Sprite& sprite, sf::Image& image, sf::Texture& texture, const char* fName, int width, int height, float positionX, float positionY)
{
    std::cout << "Loading Image From: " << fName << std::endl;
    if(!image.loadFromFile(fName))
    {
        std::cout << "Error loading from file!";
        return false;
    }
    std::cout << "File successfully loaded!" << std::endl;

    sf::IntRect rect;
    rect.width = width;
    rect.height = height;

    std::cout << "Loading texture from Image" << std::endl;;
    if(!texture.loadFromImage(image, rect))
    {
        std::cout << "Error loading texture" << std::endl;
        return false;
    }

    std::cout << "Texture loaded successfully!" << std::endl;

    sprite.setTexture(texture, false);
    sprite.setPosition(positionX, positionY);
    return true;
}

void SpriteManager::updatePlayer(Player& player, sf::Texture texture)
{
    player.setTexture(texture);
}


